<script src="<?=base_url('resources/tools/build/kalendae.js')?>" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="<?=base_url('resources/tools/build/kalendae.css')?>" type="text/css" charset="utf-8">
<script type="text/javascript">
$(document).ready(function(){
	var counter = 60;
	var interval = setInterval(function() {
	    counter--;
	    // Display 'counter' wherever you want to display it.
	    if (counter == 0) {
	        // Display a login box
	        window.location.href="<?=current_url()?>";
	        clearInterval(interval);
	    }
	}, 1000);					
	
	var $url = '<?=$this->uri->segment(3)?>';
	if($url == 'reservation'){
		$('.takeaway_normal').css('display','none');
		$('#reservation').addClass('active');
		}else if($url == 'normal'){
			$('.takeaway_reservation').css('display','none');
			$('#today').addClass('active');
			}
	
})
function order_date(id)
{
	
	if(id=='today' && !$('.takeaway_normal').is(':visible'))
	{	
		$('.takeaway_reservation').fadeOut(50,function(){
			$('#reservation').removeClass('active');
			$('#today').addClass('active');
			$(location).attr('href','<?=site_url()?>cart/takeaway/normal');
		$('.takeaway_normal').fadeIn(50);
		})
	}else if(id=='reservation' && !$('.takeaway_reservation').is(':visible'))
		{
		
		$('.takeaway_normal').fadeOut(50,function(){
			$('#today').removeClass('active');
			$('#reservation').addClass('active');
			$(location).attr('href','<?=site_url()?>cart/takeaway/reservation');
			$('.takeaway_reservation').fadeIn(50);
		}
		);
		}
	
}
function order_submit(id){
	var $date = $('#datepicker_'+id).val();
	var $time = $('#reservation_time_'+id).val();
	var $date_arrow = $('#date_arrow_'+id);
	var $time_arrow = $('#time_arrow_'+id);
	if($date !='' && $time !='null'){ 
		$('#submit_'+id).submit();
		}else{
	if($date==''){ $date_arrow.show();}else{ $date_arrow.hide(); }
	if($time=='null'){ $time_arrow.show();}else{ $time_arrow.hide(); }
	}
}
function normal_order_submit(id){
	
	var $time = $('#normal_time_'+id).val();
	if($time !='invalid'){ 
		$('#submit_normal_'+id).submit();
		}else{
		$('.error_'+id).html('fin de service');
	}
}
</script>

<div class="ctn_takeaway">

	<div class="notice">
		<p>Veuillez-vous choisir votre magazin et votre heure à emporter vos
			palts</p>
	</div>
<?php foreach ($shop as $s):?>
<div class="shop takeaway_normal" >
<h3><?=$s->shop_name?></h3>
<p><?=$s->address?></p>
<p><img src="<?=base_url()?>resources/imgs/telephone.png" height="15"  alt="telephone" title="telephone"/><?=$s->tele?><br><img src="<?=base_url()?>resources/imgs/fax.png" height="17"  alt="telephone" title="fax"/><?=$s->fax?></p>
<p><?=$s->open_day?><br><?=$s->open_hour?></p>
<div class="takeaway_time">

<?php if($s->id==2 && date('d-m-Y H:i:s')<date('25-12-2013 14:00:00')){?>
<h2 class="closed">Fermé</h2>
<?php }else{?>
<form action="" method="post" id="submit_normal_<?=$s->id?>"> 
<select name="takeaway_time" id="normal_time_<?=$s->id?>">
<?php foreach ($hours as $h):?>
<?php if($s->id==1){?><option <?php if($h->evere == null){ echo 'disabled';}elseif( time()>=strtotime('-14 minutes',strtotime($h->hour)) )
{echo 'disabled';}?> value="<?=$h->hour?>"><?php if($h->evere !=null){?><?=$h->hour?><?php }else{ echo '--:--';}?></option><?php }?>
<?php if($s->id==2){?><option <?php if($h->uccle == null){ echo 'disabled';}elseif( time()>=strtotime('-14 minutes',strtotime($h->hour)) )
{echo 'disabled';}?> value="<?=$h->hour?>"><?php if($h->uccle !=null){?><?=$h->hour?><?php }else{ echo '--:--';}?></option><?php }?>
<?php if($s->id==3){?><option <?php if($h->etterbeek == null){ echo 'disabled';}elseif( time()>=strtotime('-14 minutes',strtotime($h->hour)) )
{echo 'disabled';}?> value="<?=$h->hour?>"><?php if($h->etterbeek !=null){?><?=$h->hour?><?php }else{ echo '--:--';}?></option><?php }?>
<?php endforeach;?>
<option value="invalid" >fin de service</option>
</select>
<input type="hidden" value="<?=$s->id?>" name="shop_id">
<input type="hidden" value="normal" name="order_type">
<input type="button" value="validez" onclick="normal_order_submit(<?=$s->id?>)">
<p class="error_<?=$s->id?>"></p>
</form>

<?php }?>
</div>
</div>
<div class="shop takeaway_reservation" >
<h3><?=$s->shop_name?></h3>
<p><?=$s->address?></p>
<p><img src="<?=base_url()?>resources/imgs/telephone.png" height="15"  alt="telephone" title="telephone"/><?=$s->tele?><br><img src="<?=base_url()?>resources/imgs/fax.png" height="17"  alt="telephone" title="fax"/><?=$s->fax?></p>
<p><?=$s->open_day?><br><?=$s->open_hour?></p>
		<form id="submit_<?=$s->id?>" action="" method="post">
			<div class="order_date">

				<h4>Choisissez une date:</h4>
				<input type="text" name="datepicker_<?=$s->id?>" value=""
					id="datepicker_<?=$s->id?>"><img class="date_arrow"
					id="date_arrow_<?=$s->id?>"
					src="<?=base_url()?>resources/imgs/arrow_back_red.png" alt="arrow"
					title="arrow" width="25"><br>
				<script type="text/javascript" charset="utf-8">
		var k4 = new Kalendae.Input('datepicker_<?=$s->id?>', {
			months:2,
			direction:'future',
			blackout: function (date) {
				<?php if($s->id==3){?>
				return [1,0,0,0,0,0,0][Kalendae.moment(date).day()]; //blackout weekends
				<?php }else{?>
				return [0,0,0,0,0,0,0][Kalendae.moment(date).day()]; //blackout weekends
				<?php }?>
			}
		
		});
	</script>
			</div>
			<br>
			<div class="takeaway_time">
				<h4>A partir de:</h4>

				<select name="takeaway_time" id="reservation_time_<?=$s->id?>">
					<option value="null">Choisissez l'heure</option>
					<?php foreach ($hours as $h):?>
					<?php if($s->id==1){?>
					<option <?php if($h->evere == null){ echo 'disabled';}
					?>
						value="<?=$h->hour?>">
						<?php if($h->evere !=null){?>
						<?=$h->hour?>
						<?php }else{ echo '--:--';}?>
					</option>
					<?php }?>
					<?php if($s->id==2){?>
					<option <?php if($h->uccle == null){ echo 'disabled';}?>
						value="<?=$h->hour?>">
						<?php if($h->uccle !=null){?>
						<?=$h->hour?>
						<?php }else{ echo '--:--';}?>
					</option>
					<?php }?>
					<?php if($s->id==3){?>
					<option <?php if($h->etterbeek == null){ echo 'disabled';}?>
						value="<?=$h->hour?>">
						<?php if($h->etterbeek !=null){?>
						<?=$h->hour?>
						<?php }else{ echo '--:--';}?>
					</option>
					<?php }?>
					<?php endforeach;?>
				</select><img class="time_arrow" id="time_arrow_<?=$s->id?>"
					src="<?=base_url()?>resources/imgs/arrow_back_red.png" alt="arrow"
					title="arrow" width="25"> <input type="hidden" value="<?=$s->id?>"
					name="shop_id"> <input type="hidden" value="reservation"
					name="order_type"> <input type="button" value="validez"
					onclick="order_submit(<?=$s->id?>)">
		</div>
		</form>
	</div>


<?php endforeach;?>
<div class="clear"></div>
<div style="display:block;">
<a href="<?=site_url('cart')?>">modifiez votre commande</a>
</div>
</div>





